load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")

# We need to create a separate proto_library
# to conform with macro java_proto_library rules
proto_library(
    name = "service_proto_v1alpha1",
    srcs = ["src/main/proto/v1alpha1/service.proto"],
    deps = [
        "@com_google_protobuf//:struct_proto",
        "@com_google_protobuf//:wrappers_proto",
    ],
)

java_proto_library(
    name = "service_java_proto_v1alpha1",
    deps = [":service_proto_v1alpha1"],
)

java_grpc_library(
    name = "service_java_grpc_v1alpha1",
    srcs = [":service_proto_v1alpha1"],
    deps = [":service_java_proto_v1alpha1"],
)

java_library(
    name = "grpc_library_v1alpha1",
    srcs = glob(["src/main/java/**/*.java"]),
    deps = [
        ":service_java_grpc_v1alpha1",
        ":service_java_proto_v1alpha1",
        "@io_grpc_grpc_java//api",
    ],
)

java_binary(
    name = "client_v1alpha1",
    main_class = "com.client.BentoServiceClient",
    runtime_deps = [
        ":grpc_library_v1alpha1",
        "@io_grpc_grpc_java//netty",
    ],
)

proto_library(
    name = "service_proto",
    srcs = ["src/main/proto/v1/service.proto"],
    deps = [
        "@com_google_protobuf//:struct_proto",
        "@com_google_protobuf//:wrappers_proto",
    ],
)

java_proto_library(
    name = "service_java_proto",
    deps = [":service_proto"],
)

java_grpc_library(
    name = "service_java_grpc",
    srcs = [":service_proto"],
    deps = [":service_java_proto"],
)

java_library(
    name = "grpc-library",
    srcs = glob(["src/main/java/**/*.java"]),
    deps = [
        ":service_java_grpc",
        ":service_java_proto",
        "@io_grpc_grpc_java//api",
    ],
)

java_binary(
    name = "client",
    main_class = "com.client.BentoServiceClient",
    runtime_deps = [
        ":grpc-library",
        "@io_grpc_grpc_java//netty",
    ],
)
